home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / parallax / more_exa.tar / more / X / xmandel.p < prev    next >
Text File  |  1992-11-12  |  2KB  |  67 lines

  1. SYSTEM mandelbrot;
  2. (* Iterative Computation of Mandelbrot Set    *)
  3. (* With X Window Visualization | Braunl, 1992 *)
  4. CONST n        =   64;
  5.       max_iter =   15;
  6.       col_inc  =   255 DIV max_iter;
  7.       north    =   1.3;  south = -1.3;
  8.       west     =  -2.0;  east  =  0.6;
  9.  
  10. TYPE  complex  = RECORD re,im: REAL
  11.                  END;
  12.  
  13. CONFIGURATION list [0..n-1],[0..n-1];
  14. CONNECTION (* none *);
  15.  
  16. SCALAR win_num,col: INTEGER;
  17.        ch         : CHAR;
  18.   
  19. VECTOR c, z  : complex;
  20.        out : BOOLEAN;
  21.  
  22. PROCEDURE C_Add (VECTOR a,b: complex): VECTOR complex;
  23. VECTOR res: complex;
  24. BEGIN
  25.   res.re := a.re + b.re;
  26.   res.im := a.im + b.im;
  27.   RETURN(res);
  28. END C_Add;
  29.  
  30. PROCEDURE C_Mul (VECTOR a,b: complex): VECTOR complex;
  31. VECTOR res: complex;
  32. BEGIN
  33.   res.re := a.re*b.re - a.im*b.im;
  34.   res.im := a.re*b.im + a.im*b.re;
  35.   RETURN(res);
  36. END C_Mul;
  37.  
  38. PROCEDURE C_Col (VECTOR a: complex) : VECTOR BOOLEAN;
  39. BEGIN
  40.   RETURN (a.re*a.re + a.im*a.im > 5.0);
  41. END C_Col;
  42.  
  43. BEGIN
  44.   win_num := OpenAbswindow(n,n);
  45.   PARALLEL
  46.     WITH c DO
  47.       re := west  + FLOAT(DIM2) * ((east -west )/FLOAT(n-1)); (* real *)
  48.       im := south + FLOAT(DIM1) * ((north-south)/FLOAT(n-1)); (* imaginery *)
  49.     END;
  50.     z:=c;
  51.     col := 255; out := FALSE;
  52.  
  53.     WHILE (col > 0) AND NOT out DO
  54.       z   := C_Add( C_Mul(z,z), c );
  55.       out := C_Col(z);
  56.       SetColor(COLOR(col, col, col)); (* grayscale *)
  57.       SetPixel(DIM2,DIM1);            (* fill remaining region *)
  58.       dec(col,col_inc);
  59.     END;
  60.   ENDPARALLEL;
  61.  
  62.   WriteString("Press RETURN for termination"); WriteLn;
  63.   Read(ch);
  64.   CloseWindow(win_num);
  65. END mandelbrot.
  66.  
  67.